package net.sevear.chaos.view.setting
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.Button;
	import mx.controls.Image;
	import mx.controls.Label;
	
	import net.sevear.chaos.vo.UserInfo;
	
	import spark.components.Group;
	
	public class UserQuickSelectView2 extends Group
	{
		public static const DELETE_ELEM:String = "delete";
		
		private var _nameTxt:Label;
		private var _statLbl:Label;
		[Embed("/res/deleteContact.png")]
		private var deleteIcon:Class;
		
		private var _user:UserInfo;
		private var toLove:int;
		private var totalRe:int;
		private var deleteBtn:Image;
		
		public function UserQuickSelectView2()
		{
			super();
			this.height = 45;
			
			_nameTxt = new Label();
			_nameTxt.x = 10;
			_nameTxt.y = 0;
			this.addElement(_nameTxt);
			
			_statLbl = new Label();
			_statLbl.x = 10;
			_statLbl.y = 20;
			_statLbl.toolTip = "ta喜欢推荐数/你一共给ta推荐歌曲数";
			this.addElement(_statLbl);
			
			deleteBtn = new Image();
			deleteBtn.source = deleteIcon;
			deleteBtn.addEventListener(MouseEvent.CLICK,onClickDelete);
			deleteBtn.width = deleteBtn.height = 16;
			deleteBtn.right = 3;
			deleteBtn.top = 3;
			deleteBtn.visible = false;
			this.addElement(deleteBtn);
			
			addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
			setUserInfo(null);
			
		}
		
		public function setUserInfo(user:UserInfo):void{
			this.graphics.clear();
			if(user!=null){
				this.visible = true;
				this._user = user;
				this._nameTxt.text = _user.dbName;
				this._nameTxt.setStyle("color",_user.color);
				this._statLbl.setStyle("color",_user.color);
				//FIXME:画了但是没显示
				this.graphics.beginFill(_user.color);
				this.graphics.drawRect(0,0,this.width,this.height);
				this.graphics.endFill();
				
				_statLbl.text = "";
			}else{
				this._user = null;
				this.toLove  = 0;
				this.totalRe = 0;
				this.visible = false;
			}
		}
		
		public function get userInfo():UserInfo{
			return _user;
		}
		
		public function setRecommendRate(toLove:int,totalRecommend:int):void{
			_statLbl.text = toLove+"/"+totalRecommend;
		}
		
		private function onClickDelete(e:MouseEvent):void{
			dispatchEvent(new Event(DELETE_ELEM));
		}
		
		private function onMouseOver(e:MouseEvent):void{
			deleteBtn.visible = true;
		}
		
		private function onMouseOut(e:MouseEvent):void{
			deleteBtn.visible = false;
		}
	}
}